home *** CD-ROM | disk | FTP | other *** search
- #include "ICAPI.h"
- #include "ICKeys.h"
- #include "ICMappings.h"
- #include "ICSubs.h"
-
- typedef struct {
- unsigned char extension[6];
- OSType fType;
- OSType fCreator;
- short reserved;
- }typeRec;
-
- typedef struct {
- short numTypes;
- typeRec theTypes[1];
- }typeListRec, **typeListRecH;
-
- void InitToolbox (void)
- {
- InitGraf ( &qd.thePort );
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (NULL); // use of ResumeProcs no longer approved by Apple
- InitCursor ();
- FlushEvents ( everyEvent, 0 );
-
- // how about some memory fun! Two should be enough!
- MoreMasters ();
- MoreMasters ();
- }
-
-
- void main(void)
- {
- ICInstance inst;
- ICAttr attr = 0;
- ICError err;
- ICMapEntry entry;
- Handle mappings = nil;
- long prefsize = 0;
- typeListRecH tlrH = nil;
- SFTypeList typeList;
- StandardFileReply reply;
-
- InitToolbox();
-
- StandardGetFile(nil, -1, typeList, &reply); // standardfile.h
- if (!reply.sfGood) return;
-
- if (!ICStart(&inst, 'ICMa')) { // init the sucker
- if (!ICFindConfigFile(inst, 0, nil)) { // locate the config file
- if (!ICBegin(inst, icReadOnlyPerm)) { // open up the file for reading
- if (!ICGetPrefHandle(inst, (ConstStr255Param)kICMapping, &attr, &mappings)) { // get the size
- long pos = 0, count, i = 0;
-
- // first things first - found out how many to preflight memory allocation
- err = ICMCountEntries(mappings, &count);
- if (!err && count) {
- tlrH = (typeListRecH)NewHandle(count * sizeof(typeRec) + sizeof(short));
- if (tlrH) {
- HLock((Handle)tlrH);
- (*tlrH)->numTypes = count-1; // -1 for 0 based count
-
- err = ICMGetEntry(mappings, pos, &entry);
- do {
- // copy the info out to the typeListH
- BlockMoveData(entry.extension, (*tlrH)->theTypes[i].extension, 6);
- (*tlrH)->theTypes[i].fType = entry.file_type;
- (*tlrH)->theTypes[i].fCreator = entry.file_creator;
- (*tlrH)->theTypes[i].reserved = 1;
-
- // and get the next one!
- i++;
- pos += entry.total_length;
- err = ICMGetEntry(mappings, pos, &entry);
- } while (err == noErr);
-
- // open up the file and add the resource
- {
- short refNum = FSpOpenResFile(&reply.sfFile, fsRdWrPerm); // resources.h
- Handle tmpH = Get1Resource('E2Ty', 0);
-
- if (tmpH) {
- SetHandleSize(tmpH, GetHandleSize((Handle)tlrH));
- BlockMoveData((Ptr)*tlrH, *tmpH, GetHandleSize((Handle)tlrH));
- ChangedResource(tmpH);
- WriteResource(tmpH);
- DisposHandle((Handle)tlrH);
- } else {
- AddResource((Handle)tlrH, 'E2Ty', 0, "\p");
- WriteResource((Handle)tlrH);
- ReleaseResource((Handle)tlrH);
- }
- CloseResFile(refNum);
- }
- } else
- err = MemError();
- }
-
- DisposHandle(mappings);
- } else
- StopAlert(129, 0L);
-
- ICEnd(inst); // all done
- } else
- StopAlert(129, 0L);
- } else
- StopAlert(129, 0L);
-
- ICStop(inst); // all done
- } else
- StopAlert(128, 0L);
- }
-